package com.tfy.liquor.dao;

import com.tfy.liquor.bean.VendorInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * 供应商信息
 */
@Mapper
@Service
public interface VendorInfoDao {
    // 添加供应商信息
    @Insert("insert into vendor_info values(null, '${vendorName}', '${userName}', '${mobile}', '${email}', 0, '${remark}', '${createTime}')")
    int addVendorInfo(VendorInfo vendorInfo);

    // 根据条件查询供应商信息
    @Select("<script>" +
            "select * from vendor_info " +
            "where 1=1" +
            "<if test='id != null'> and id = ${id}</if>" +
            "<if test='vendorName != null'> and vendorName like '%${vendorName}%'</if>" +
            "<if test='mobile != null'> and mobile = '${mobile}'</if>" +
            "</script>")
    ArrayList<VendorInfo> getAllVendorInfo(VendorInfo vendorInfo);

    // 获取添加产品时展示的供应商信息
    @Select("select id, vendorName from vendor_info where status=0")
    ArrayList<VendorInfo> getVendorInfo();

    // 修改供应商信息
    @Update("update vendor_info set vendorName='${vendorName}', userName='${userName}', mobile='${mobile}', email='${email}', status=${status}, remark='${remark}' where id=${id}")
    int editVendorInfo(VendorInfo vendorInfo);

    // 修改供应商状态
    @Update("update vendor_info set status=${status} where id=${id}")
    int editVendorInfoStatus(VendorInfo vendorInfo);

}
